# -*- coding: utf-8 -*-
import numpy as np
import os, cv2, time, copy, random
# from tools.aug_paper import *
# from tools.temp import *
from tools.utils import *
config = Config()


if __name__ == '__main__':
    """
    Demo1: 根据给定的原始模板、检测、文本框mask三张图片后，根据文本框mask图片对数据进行crop到指定尺寸，
    便于OD模型训练存储图片命名方式：图片名称_temp.bmp, 图片名称_insp.bmp, 图片名称_text.bmp
    涉及调试参数：
    1）is_back
    2）random_crop
    """

    input_root = r"D:\0_Data\1_pure"
    output_root = r"D:\1_Chen\printing_simulator\sim_result\defect_offline\1_ori_back"
    is_back = True        # 生成的数据是背景还是文字区域
    random_crop = True    # 在遍历收集样本不充足时，可以通过随机裁切无限生成数据
    crop_num = 20         # random_crop为True时，可设置裁切数量
    crop_size_list = [832, 1024, 1280, 'all']  # 根据列表指定的裁切尺寸依次裁切，最后生成在'all'文件夹内，即output_root/all
    if random_crop is True:
        special_back_name, special_text_name = 'back_randomNew_', 'text_randomNew_'
    else:
        special_back_name, special_text_name = 'backNew_', 'textNew_'
    for size_name in crop_size_list:
        if isinstance(size_name, int):  # 如果当前字段是数字
            # special_name = special_back_name + str(size_name) if is_back is True else special_text_name + str(size_name)
            # crop_size = (size_name, size_name)
            # create_output_root = os.path.join(output_root, str(size_name))
            # os.makedirs(create_output_root, exist_ok=True)
            # run_with_threads(input_root,
            #                  create_output_root,
            #                  is_back=is_back,
            #                  special_name=special_name,
            #                  window_size=crop_size,
            #                  random_crop=random_crop,
            #                  crop_count=crop_num, is_gen_online=config.IS_GEN_ONLINE)
            pass
        else:  # 如果当前是all字段
            number_list = [size for size in crop_size_list if isinstance(size, int)]
            for size in number_list:
                special_name = special_back_name + str(size) if is_back is True else special_text_name + str(size)
                crop_size = (size, size)
                create_output_root = os.path.join(output_root, size_name)
                os.makedirs(create_output_root, exist_ok=True)
                run_with_threads(input_root,
                                 create_output_root,
                                 is_back=is_back,
                                 special_name=special_name,
                                 window_size=crop_size,
                                 random_crop=random_crop,
                                 crop_count=crop_num, is_gen_online=config.IS_GEN_ONLINE)
            print("bingo....")



